/*
 * Copyright (C) 2003, Velocityme Partnership
 * UserBean.java
 *
 * Created on 30 March 2003, 05:33
 */

package com.velocityme.entity;

import javax.ejb.*;
import javax.naming.*;
import java.rmi.*;
import javax.rmi.*;
import com.velocityme.interfaces.*;
import com.velocityme.valueobjects.UserValue;
import com.velocityme.interfaces.ServiceUnavailableException;

/**
 * @author  Robert Crida Work
 * @ejb.bean
 *           type="CMP"
 *           cmp-version="2.x"
 *           name="User"
 *           jndi-name="ejb/User"
 *           view-type="local"
 * @ejb.transaction type="Required"
 *
 * @ejb.value-object match="nopassword"
 *
 * @ejb.persistence table-name="xuser"
 *
 * @ejb.util generate="physical"
 *
 * @ejb.finder signature="java.util.Collection findAll()"
 *              query="SELECT OBJECT(o) FROM User o WHERE o.nodeLocal.dBObjectLocal.isDeleted = FALSE"
 *
 * @ejb.finder signature="com.velocityme.interfaces.User findByUsername(java.lang.String userName)"
 *              query="SELECT OBJECT(o) FROM User o WHERE o.userName = ?1"
 *
 * @jboss.persistence create-table="true"
 *                    remove-table="false"
 */
public abstract class UserBean implements EntityBean {
    
    /**
    * Context set by container
    */
    private javax.ejb.EntityContext m_entityContext;

    public void setEntityContext(javax.ejb.EntityContext entityContext) {
        m_entityContext = entityContext;
    }

    public void unsetEntityContext() {
        m_entityContext = null;
    }
  
    /** @ejb.create-method */
    public com.velocityme.interfaces.UserPK ejbCreate(com.velocityme.interfaces.NodeLocal p_nodeLocal,
                                                      com.velocityme.valueobjects.UserValue p_value) throws CreateException {
        setUserId(p_nodeLocal.getNodeId());
        // EJB 2.0 spec says return null for CMP ejbCreate methods.
        return null;
    }

    public void ejbPostCreate(com.velocityme.interfaces.NodeLocal p_nodeLocal,
                              com.velocityme.valueobjects.UserValue p_value) throws CreateException {
        // CMR relations must be set in ejbPostCreate
        setUserValue(p_value);
        setNodeLocal(p_nodeLocal);
    }

    /**
     *  This gets a local object from a remote object.
     *  @ejb.interface-method view-type="remote"
     */
    public com.velocityme.interfaces.UserLocal getLocal() {
        return (UserLocal)m_entityContext.getEJBLocalObject();
    }
    
    /** @ejb.interface-method view-type="local" */
    public abstract com.velocityme.valueobjects.UserValue getUserValue();
    /** @ejb.interface-method view-type="local" */
    public abstract void setUserValue(com.velocityme.valueobjects.UserValue p_value);
    
    //=======================================================================
    //
    //                   ATTRIBUTES
    //
    //=======================================================================
      
    /**
     * @ejb.persistence column-name="userId"
     * @ejb.interface-method view-type="local"
     * @ejb.pk-field 
     * @ejb.value-object match="nopassword"
     */
    public abstract java.lang.Integer getUserId();
    /** @ejb.interface-method view-type="local" */
    public abstract void setUserId(java.lang.Integer userId);

    /**
     * @ejb.persistence column-name="userName"
     * @ejb.interface-method view-type="local"
     * @ejb.value-object match="nopassword"
     */
    public abstract java.lang.String getUserName();
    /** @ejb.interface-method view-type="local" */
    public abstract void setUserName(java.lang.String userName);

     /**
     * @ejb.persistence column-name="password"
     * @ejb.interface-method view-type="local"
     */
    public abstract java.lang.String getPassword();
    /** @ejb.interface-method view-type="local" */
    public abstract void setPassword(java.lang.String password);
    
    /**
     * @ejb.persistence column-name="isEnabled"
     * @ejb.interface-method view-type="local"
     * @ejb.value-object match="nopassword"
     */
    public abstract java.lang.Boolean getIsEnabled();
    /** @ejb.interface-method view-type="local" */
    public abstract void setIsEnabled(java.lang.Boolean isEnabled);

    /**
     * @ejb.persistence column-name="showBookmarks"
     * @ejb.interface-method view-type="local"
     * @ejb.value-object match="nopassword"
     */
    public abstract java.lang.Boolean getShowBookmarks();
    /** @ejb.interface-method view-type="local" */
    public abstract void setShowBookmarks(java.lang.Boolean showBookmarks);

    
    //=======================================================================
    //
    //                   RELATIONSHIPS
    //
    //=======================================================================
    
    /**
     * @ejb.interface-method view-type="local"
     * @ejb.relation name="User-Node"
     *               role-name="User-has-a-Node"
     *               target-ejb="Node"
     *               target-role-name="Node-has-a-User"
     *               target-multiple="no"
     * @jboss.relation fk-column="nodeIdFk"
     *                 related-pk-field="nodeId"
     * @ejb.value-object match="nopassword" 
     *                   aggregate="com.velocityme.valueobjects.NodeValue"
     *                   aggregate-name="NodeValue"
     */
    public abstract com.velocityme.interfaces.NodeLocal getNodeLocal();
    /** @ejb.interface-method view-type="local" */
    public abstract void setNodeLocal(com.velocityme.interfaces.NodeLocal nodeLocal);
    
    /**
     * @ejb.interface-method view-type="local"
     * @ejb.relation name="Person-User"
     *               role-name="User-has-a-Person"
     * @jboss.relation fk-column="personIdFk"
     *                 related-pk-field="personId"
     * @ejb.value-object match="nopassword" 
     *                   aggregate="com.velocityme.valueobjects.PersonValue"
     *                   aggregate-name="PersonValue"
     */
    public abstract com.velocityme.interfaces.PersonLocal getPersonLocal();
    /** @ejb.interface-method view-type="local" */
    public abstract void setPersonLocal(com.velocityme.interfaces.PersonLocal person);
    
    /**
     * @ejb.interface-method view-type="local"
     * @ejb.relation name="UserAccess-User"
     *               role-name="User-may-have-many-UserAccesses"
     */
    public abstract java.util.Collection getUserAccessesLocal();
    /** @ejb.interface-method view-type="local" */
    public abstract void setUserAccessesLocal(java.util.Collection userAccessesLocal);
    
    /**
     * @ejb.interface-method view-type="local"
     * @ejb.relation name="User-Group"
     *               role-name="User-may-have-many-Groups"
     * @jboss.relation fk-column="userId"
     *                 related-pk-field="groupId"
     */
    public abstract java.util.Collection getGroupsLocal();
    /** @ejb.interface-method view-type="local" */
    public abstract void setGroupsLocal(java.util.Collection groupsLocal);
    
    /**
     * @ejb.interface-method view-type="local"
     * @ejb.relation name="User-Login"
     *               role-name="User-has-many-Logins"
     */
    public abstract java.util.Collection getLoginsLocal();
    /** @ejb.interface-method view-type="local" */
    public abstract void setLoginsLocal(java.util.Collection loginsLocal);
    
    /**
     * @ejb.interface-method view-type="local"
     * @ejb.relation name="User-BookmarkNode"
     *               role-name="User-has-many-BookmarkNodes"
     * @jboss.relation fk-column="userId"
     *                 related-pk-field="nodeId"
     * @jboss.relation-table table-name="userbookmarknode"
     *                       create-table="true"
     *                       remove-table="false"
     */
    public abstract java.util.Set getBookmarkNodesLocal();
    /** @ejb.interface-method view-type="local" */
    public abstract void setBookmarkNodesLocal(java.util.Set bookmarkNodes);
    
    //=======================================================================
    //
    //                   MANAGEMENT METHODS
    //
    //=======================================================================
    
    /**
     *  @ejb.interface-method view-type="local"
     */
    public java.lang.String getPersonUserName() {
        return getPersonLocal().getContactableLocal().getNodeLocal().getName() + ":" + getNodeLocal().getName();
    }
    
}
